{% extends 'obj_form.html' %} {% load i18n %} {% load tj_filters %} {% block js %} {{ block.super }} /* $('#div_label,#subdiv_label,.add-div,.add-subdiv').attr("disabled",true); */ {% ifnotequal user.company.level_id 1%} {% if not user.perms.company.sys_admin%} $('#data-content input,#data-content .btn,#data-content select').attr("disabled",true); {% endif %} {% endifnotequal %} {% if form.instance.company %} $('#co').val('{{form.instance.company.id}}'); $('#id_channelrebate_promotion-__prefix__-company').val('{{form.instance.company}}'); {% else %} $('#co').val(''); $('#product_label,#agent_label,#div_label,#subdiv_label').attr("disabled","disabled"); {% endif %} $('#co').change(function(){ $('#id_company').val($(this).val()); var b; if($('#co').val()==''){ b=true; }else{ b=false; } $('#product_label,#agent_label,#div_label,#subdiv_label').attr("disabled",b) }); $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'}); //$('.datepicker').datepicker('setDate',new Date()); setDatePickerZh(); $.datetimepicker.setLocale('zh'); $('.datetimepicker').datetimepicker({ i18n:{ zh:{ months:['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月',], dayOfWeek:["一", "二", "三", "四","五", "六", "日",] } }, //timepicker:true, format:'Y-m-d H:i:s', }); $('#product_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/product/', dataType: "json", data: { term: $("#product_label").val() ,//搜索栏里的内容 company_id: $('#co').val() ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#product_id").val(ui.item.value); $("#product_label").val(ui.item.label); return false; } }); $('#agent_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/agent/', dataType: "json", data: { term: $("#agent_label").val() ,//搜索栏里的内容 company_id: $('#co').val() ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#agent_id").val(ui.item.value); $("#agent_label").val(ui.item.label); return false; } }); $('#div_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/saldiv/', dataType: "json", data: { term: $("#div_label").val() ,//搜索栏里的内容 company_id: $('#co').val() ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#div_id").val(ui.item.value); $("#div_label").val(ui.item.label); //2020-10-19 get_subdivs(ui.item.value); return false; } }); //$('#subdiv_label').autocomplete({ // source: function(request, response) { // $.ajax({ // url: '/obj/ajax/autocomplete/subdiv/', // dataType: "json", // data: { // term: $("#subdiv_label").val() ,//搜索栏里的内容 // company_id: $('#co').val() ,//额外参数 // }, // success: function(data) { // response(data); // } // }); // }, // select: function (event, ui) { // $("#subdiv_id").val(ui.item.value); // $("#subdiv_label").val(ui.item.label); // return false; // } //}); $('#div_id').change(function(){ var saldiv_id=$(this).val(); if (saldiv_id==''){ $('#subdiv_id').empty(); $('#subdiv_id').append('') }else{ get_subdivs($(this).val()); } }); function get_subdivs(saldiv_id){ var me=$('#subdiv_id'); $.ajax({ url: "/obj/ajax/subsaldiv/"+saldiv_id+"/", success: function(data) { $(me).empty(); $.each(data,function(i,d){$(me).append("")}); }, dataType: 'json' }); }; $('.add-product').click(function(){ var id=$('#product_id').val(); var label=$('#product_label').val(); if(id==''){ toastr.error("请先选择产品!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-product option").each(function(){ if($(this).val() == id){ e=true; return false; } }); if(e){ toastr.error(label+"已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ $('#sel-product').append(""); } }; }); $('.add-agent').click(function(){ var id=$('#agent_id').val(); var label=$('#agent_label').val(); if(id==''){ toastr.error("请先选择经销商!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-agent option").each(function(){ if($(this).val() == id){ e=true; return false; } }); if(e){ toastr.error(label+"已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ $('#sel-agent').append(""); } }; }); $('.add-div').click(function(){ var id=$('#div_id').val(); {% ifequal user.id 1 %} var label=$('#div_label').val(); {% else %} var label=$('#div_id').find("option:selected").text(); {% endifequal %} if(id==''){ toastr.error("请先选择战区!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-div option").each(function(){ if($(this).val() == id){ e=true; return false; } }); if(e){ toastr.error(label+"已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ $('#sel-div').append(""); } }; }); $('.add-subdiv').click(function(){ var id=$('#subdiv_id').val(); {% ifequal user.id 1 %} var label=$('#subdiv_label').val(); {% else %} var label=$('#subdiv_id').find("option:selected").text(); {% endifequal %} if(id==''){ toastr.error("请先选择分区!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-subdiv option").each(function(){ if($(this).val() == id){ e=true; return false; } }); if(e){ toastr.error(label+"已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ $('#sel-subdiv').append(""); } }; }); $('.add-rebate').click(function(){ var prefix='#id_channelrebate_promotion-'; var count = $('#formset').find('.rebate').length; var tmplMarkup = $('#empty-form').html(); var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count); $('#formset').append(compiledTmpl); $(prefix+'TOTAL_FORMS').attr('value', (count+1)); }); $('#obj_form').on('click','.add-pval',function(){ var div=$(this).closest('.rebate'); var sel=$(div).find('.sel-plv'); var id=sel.val(); var label=sel.find("option:selected").text(); var e=false; var val=$(div).find('.pval').val(); if($.isEmpty(id)){ toastr.error("营销层级不能为空", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }; if(val==''){ toastr.error("未输入层级返利金额", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }; $(div).find(".sel-plvs option").each(function(){ if($(this).val() == id){ e=true; return false; } }); if(e){ toastr.error(label+"已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ $(div).find('.sel-plvs').append(""); }; //2020-11-03 $('#formset .select2_multiple').on('dblclick','option',function(){ $(this).remove(); }); }); $('#obj_form').on('change','.sel-lv',function(){ var me=$(this); $.ajax({ url: '/company/ajax/parent/level/'+$(this).val()+'/', dataType: "json", success: function(data) { var div=$(me).closest('.rebate'); var html=''; var lv,b; for(i in data.parents){ lv=data.parents[i]; html=html+""; }; $(div).find('.sel-plv').html(html); if(html==''){ b=true; }else{ b=false } $(div).find('.add-pval').attr('disabled',b); } }); }); $('.btn-save').click(function(){ if($.isEmpty($('#id_company').val()) || $.isEmpty($('#id_tm_start').val()) || $.isEmpty($('#id_tm_end').val()) || $.isEmpty($('#id_name').val())){ toastr.error("公司名称,活动名称,开始时间,结束时间 不能为空", "操作错误:", {timeOut: 1800, positionClass: "toast-center-center"} ); return; }; var a=[]; var s=''; $("#formset .rebate").each(function (){ a=[]; var me=$(this); $(me).find('.sel-plvs option').each(function(){ s=$(this).val()+'|'+$(this).attr('o-rc')+'|'+$(this).attr('o-vl')+'|'+$(this).attr('o-nm'); a.push(s); }); if(a.length>0){ $(me).find('.pvals').val(a.join('&')); }; }); a=[]; $("#sel-product option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_products').val(a.join(',')); }else{ $('#id_products').val(''); }; a=[]; $("#sel-agent option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_agents').val(a.join(',')); }else{ $('#id_agents').val(''); }; a=[]; $("#sel-div option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_div_ids').val(a.join(',')); }else{ $('#id_div_ids').val(''); }; a=[]; $("#sel-subdiv option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_subdiv_ids').val(a.join(',')); }else{ $('#id_subdiv_ids').val(''); }; $.SubmitForm('#obj_form form','{{request.path}}'); }); {% for f in formset %} var prefix='#id_channelrebate_promotion-'; var count = $('#formset').find('.rebate').length; var tmplMarkup = $('#empty-form').html(); var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count); $('#formset').append(compiledTmpl); $(prefix+count+'-id').val('{{f.instance.id}}'); $(prefix+count+'-level').val('{{f.instance.level.id}}'); $(prefix+count+'-vtype_id').val('{{f.instance.vtype_id}}'); $(prefix+count+'-val').val('{{f.instance.val}}'); $(prefix+count+'-distance').val('{{f.instance.distance}}'); if("{{f.instance.pvals|default_if_none:''}}".length>0){ var html=''; var aa='{{f.instance.pvals}}'.split('&'); for(i=0;i"+a[3]+':'+a[2]+""; }; $(prefix+count).find('.sel-plvs').html(html); }; $(prefix+'TOTAL_FORMS').attr('value', (count+1)); {% endfor %} //2020-11-06 $('#data-content [data-toggle="tooltip"]').tooltip(); {% endblock %} {% block subtitle-1 %} {% trans "营销活动" %} {% endblock %} {% block subtitle-2 %} {% trans "返利方案" %} {% endblock %} {% block subtitle-3 %} {% if form.instance.id %} {% trans "修改" %} {% else %} {% trans "新建" %} {% endif %} {% endblock %} {% block form_content %} {{ block.super }}
{{ form.name }}
{{ form.awardcategory }}
{{ form.priority }}
{% ifequal user.id 1 %} {% else %} {% endifequal %}
{{ form.tm_start }}
{{ form.tm_end }}
{{ form.dt_delivery }}
{{ form.status }}
{{ form.digest }}
{% endblock %} {% block extra %}
{{ form.package_unit }}
{% trans '添加扫码场景' %} {% trans '保存活动设置' %}
{% endblock %} {% block fmset %}
{{ formset.management_form }}
{% endblock %}